package com.zhika.zishi.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.zhika.zishi.R;
import com.zhika.zishi.adapter.ChannelFragmentAdpter;
import com.zhika.zishi.beans.recommend.RecommendStrategyBean;
import com.zhika.zishi.constant.OthersConstant;
import com.zhika.zishi.customview.ChooseHomepageView;
import com.zhika.zishi.customview.TitleView;
import com.zhika.zishi.fragments.channel.ChannelCompareFragment;
import com.zhika.zishi.fragments.channel.ChannelItemFragment;
import com.zhika.zishi.interfaces.ChooseHomepageInterface;
import com.zhika.zishi.interfaces.TitleInterface;
import com.zhika.zishi.util.ActivityCollector;
import com.zhika.zishi.util.LogUtil;

import java.util.ArrayList;

/**
 * Created by shi-02 on 2015/4/13.
 * 频道
 */
public class ChannelActivity extends FragmentActivity implements TitleInterface {

    private static final String TAG = "ChannelActivity";

    private ViewPager viewPager;

    private PagerTabStrip pagerTabStrip;

    private ChannelFragmentAdpter channelFragmentAdpter;

    private ArrayList<String> tabList = new ArrayList<>();

    private ArrayList<Fragment> fragmentList = new ArrayList<>();

    private ArrayList<RecommendStrategyBean> beanList1 = new ArrayList<>();
    private ArrayList<RecommendStrategyBean> beanList2 = new ArrayList<>();
    private ArrayList<RecommendStrategyBean> beanList3 = new ArrayList<>();
    private ArrayList<RecommendStrategyBean> beanList4 = new ArrayList<>();
    private ArrayList<RecommendStrategyBean> beanList5 = new ArrayList<>();

    private TitleView titleView;

    private ChooseHomepageView chooseHomepageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.channel_layout);
        ActivityCollector.addActivity(this);

        addTestData();

        initView();

    }

    private void initView() {
        viewPager = (ViewPager) findViewById(R.id.channel_view_pager);
        pagerTabStrip = (PagerTabStrip) findViewById(R.id.channel_pager_tab_strip);
        pagerTabStrip.setTabIndicatorColor(getResources().getColor(R.color.color_gray));
        channelFragmentAdpter = new ChannelFragmentAdpter(getSupportFragmentManager(), fragmentList, tabList);
        viewPager.setAdapter(channelFragmentAdpter);
        viewPager.setCurrentItem(600);

        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i2) {
                chooseHomepageView.setVisibility(View.GONE);
                LogUtil.e(TAG, "onPageScrolled");
            }

            @Override
            public void onPageSelected(int i) {
                chooseHomepageView.setVisibility(View.GONE);
                LogUtil.e(TAG, "onPageSelected");
            }

            @Override
            public void onPageScrollStateChanged(int i) {
                chooseHomepageView.setVisibility(View.GONE);
                LogUtil.e(TAG, "onPageScrollStateChanged");
            }
        });
        titleView = (TitleView) findViewById(R.id.channel_title_view);
        titleView.setTitleViewInterface(this);
        titleView.setMiddleRowText("频道");

        chooseHomepageView = (ChooseHomepageView) findViewById(R.id.channel_choose_homepage_view);
        chooseHomepageView.setFirstText("好友动态");
        chooseHomepageView.setSecondText("推荐");
        chooseHomepageView.setChooseHomepageInterface(new ChooseHomepageInterface() {
            @Override
            public void firstHomepageTextListener() {
                Intent intent = new Intent(ChannelActivity.this, FriendsDynamicActivity.class);
                startActivity(intent);
            }

            @Override
            public void secondHomepageTextListener() {
                Intent intent = new Intent(ChannelActivity.this, RecommendHomepageActivity.class);
                startActivity(intent);
            }
        });
    }

    private void addTestData() {
        tabList.add("生活");
        tabList.add("女神进化论");
        tabList.add("娱乐");
        tabList.add("电影");
        tabList.add("时尚");
        tabList.add("对比秀");

        addTestData1();
        ChannelItemFragment channel1 = new ChannelItemFragment();
        Bundle data = new Bundle();
        data.putSerializable(OthersConstant.KEY_1,beanList1);
        channel1.setArguments(data);
        fragmentList.add(channel1);

        addTestData2();
        ChannelItemFragment channel2 = new ChannelItemFragment();
        Bundle data2 = new Bundle();
        data2.putSerializable(OthersConstant.KEY_1,beanList2);
        channel2.setArguments(data2);
        fragmentList.add(channel2);

        addTestData3();
        ChannelItemFragment channel3 = new ChannelItemFragment();
        Bundle data3 = new Bundle();
        data3.putSerializable(OthersConstant.KEY_1,beanList3);
        channel3.setArguments(data3);
        fragmentList.add(channel3);

        addTestData4();
        ChannelItemFragment channel4 = new ChannelItemFragment();
        Bundle data4 = new Bundle();
        data4.putSerializable(OthersConstant.KEY_1,beanList4);
        channel4.setArguments(data4);
        fragmentList.add(channel4);

        addTestData5();
        ChannelItemFragment channel5 = new ChannelItemFragment();
        Bundle data5 = new Bundle();
        data5.putSerializable(OthersConstant.KEY_1,beanList5);
        channel5.setArguments(data5);
        fragmentList.add(channel5);

        ChannelCompareFragment channel6 = new ChannelCompareFragment();
        fragmentList.add(channel6);



//        ChannelItemFragment channel2 = new ChannelItemFragment();
//        ChannelItemFragment channel3 = new ChannelItemFragment();
//        ChannelItemFragment channel4 = new ChannelItemFragment();
//        ChannelItemFragment channel5 = new ChannelItemFragment();
//        fragmentList.add(new ChannelItemFragment());
//        fragmentList.add(new ChannelItemFragment());
//        fragmentList.add(new ChannelItemFragment());
//        fragmentList.add(new ChannelItemFragment());
//        fragmentList.add(new ChannelItemFragment());
    }
    private void addTestData1(){
        for (int i = 0;i<10;i++){
            RecommendStrategyBean bean = new RecommendStrategyBean();
            bean.setHobbyStr("11社交");
            bean.setStrategy("11攻略标题攻略标题攻略标题");
            bean.setContentStr("11攻略内容攻略内容攻略内容攻略内容攻略内容攻略内容攻略内容");
            bean.setPictureUrlStr("11ddd");
            bean.setCommentNumStr("1144");
            bean.setCollectNumStr("1122");
            bean.setLikeNumStr("111");

            beanList1.add(bean);

        }
    }
    private void addTestData2(){
        for (int i = 0;i<10;i++){
            RecommendStrategyBean bean = new RecommendStrategyBean();
            bean.setHobbyStr("22社交");
            bean.setStrategy("22攻略标题攻略标题攻略标题");
            bean.setContentStr("22攻略内容攻略内容攻略内容攻略内容攻略内容攻略内容攻略内容");
            bean.setPictureUrlStr("22ddd");
            bean.setCommentNumStr("2244");
            bean.setCollectNumStr("1122");
            bean.setLikeNumStr("111");

            beanList2.add(bean);

        }
    } private void addTestData3(){
        for (int i = 0;i<10;i++){
            RecommendStrategyBean bean = new RecommendStrategyBean();
            bean.setHobbyStr("33社交");
            bean.setStrategy("33攻略标题攻略标题攻略标题");
            bean.setContentStr("33攻略内容攻略内容攻略内容攻略内容攻略内容攻略内容攻略内容");
            bean.setPictureUrlStr("33ddd");
            bean.setCommentNumStr("1144");
            bean.setCollectNumStr("1122");
            bean.setLikeNumStr("111");

            beanList3.add(bean);

        }
    } private void addTestData4(){
        for (int i = 0;i<10;i++){
            RecommendStrategyBean bean = new RecommendStrategyBean();
            bean.setHobbyStr("44社交");
            bean.setStrategy("44攻略标题攻略标题攻略标题");
            bean.setContentStr("44攻略内容攻略内容攻略内容攻略内容攻略内容攻略内容攻略内容");
            bean.setPictureUrlStr("44ddd");
            bean.setCommentNumStr("1144");
            bean.setCollectNumStr("1122");
            bean.setLikeNumStr("111");

            beanList4.add(bean);

        }
    }private void addTestData5(){
        for (int i = 0;i<10;i++){
            RecommendStrategyBean bean = new RecommendStrategyBean();
            bean.setHobbyStr("55社交");
            bean.setStrategy("55攻略标题攻略标题攻略标题");
            bean.setContentStr("55攻略内容攻略内容攻略内容攻略内容攻略内容攻略内容攻略内容");
            bean.setPictureUrlStr("55ddd");
            bean.setCommentNumStr("1144");
            bean.setCollectNumStr("1122");
            bean.setLikeNumStr("111");

            beanList5.add(bean);

        }
    }


    @Override
    public void leftTitleListener() {
        Intent intent = new Intent(ChannelActivity.this,MySelfInfoActivity.class);
        startActivity(intent);
    }

    @Override
    public void middleTitleListener() {
        chooseHomepageView.setVisibility(View.VISIBLE);
    }

    @Override
    public void rightTitleListener() {
        Intent intent = new Intent(ChannelActivity.this,SearchActivity.class);
        startActivity(intent);
    }

    @Override
    protected void onDestroy() {
        ActivityCollector.remoteActivity(this);
        super.onDestroy();
    }
}
